//
//  FQDRefreshFooter.m
//  FakeQDaily
//
//  Created by mewxiv on 8/19/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDRefreshFooter.h"
#import "FQDDotLoadingView.h"

@interface FQDRefreshFooter ()
// 三个小黄点的loading动态图
@property (nonatomic, strong) FQDDotLoadingView *loadingView;
@end

@implementation FQDRefreshFooter

#pragma mark - Custom views creation and layout
- (void)prepare
{
    [super prepare];
    
    self.mj_h = 85.0f;
    self.triggerAutomaticallyRefreshPercent = 0;
    self.automaticallyHidden = YES;
    
    self.loadingView = [[FQDDotLoadingView alloc] init];
    self.loadingView.hidden = YES;
    [self addSubview:self.loadingView];
}

- (void)placeSubviews
{
    [super placeSubviews];
    
    self.loadingView.frame = self.bounds;
}

#pragma mark - Observing refresh state
- (void)setState:(MJRefreshState)state
{
    MJRefreshCheckState;
    
    switch (state) {
        case MJRefreshStateIdle:
            [self stopLoadingAnimation];
            break;
        case MJRefreshStateRefreshing:
            [self startLoadingAnimation];
            break;
        case MJRefreshStateNoMoreData:
            [self stopLoadingAnimation];
            break;
        default:
            break;
    }
}

#pragma mark - Loading animation methods
- (void)startLoadingAnimation
{
    self.loadingView.hidden = NO;
    [self.loadingView startAnimating];
}

- (void)stopLoadingAnimation
{
    self.loadingView.hidden = YES;
    [self.loadingView stopAnimating];
}

@end
